package sporteam.web.server;

import java.util.ArrayList;

import javax.jdo.PersistenceManager;

import sporteam.common.PMF;
import sporteam.web.client.AEuser;
import sporteam.web.client.Activity;
import sporteam.web.client.GetActivitiesFromDBService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;

@SuppressWarnings("serial")
public class GetActivitiesFromDBServiceImpl extends RemoteServiceServlet
		implements GetActivitiesFromDBService {

	@Override
	public ArrayList<Activity> getActivities(String access_token) {
		FacebookClient facebookClient = new DefaultFacebookClient(
				access_token);	//establish connection with facebook-graph API with a specific access_token
		com.restfb.types.User facebook_user = facebookClient.fetchObject("me",
				com.restfb.types.User.class);	//me - the facebook user logged in ATM.
		PersistenceManager pm = PMF.get()
				.getPersistenceManager();
		AEuser returnUser = pm.getObjectById(AEuser.class, facebook_user.getId());
		
		return new ArrayList<Activity>(returnUser.GetActivities());
	}

}
